package mall

import (
	"e_mall_server/service"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
	"strconv"
)

/**
 * @Author: zhaobin
 * @Description TODO
 * @Date: 2022-05-13 17:01
 */

// GetGoodsCateList 获取商品分类列表接口
func GetGoodsCateList(c *gin.Context) {

	// 判断当前的分类id是几级分类，如果是二级分类则找到其parent_id
	idStr := c.Param("id")
	id, err := strconv.ParseInt(idStr, 10, 64)
	// 如果是二级分类则返回其parent_id，否则id不变
	id = service.GetGoodsCateParentId(id)
	zap.L().Debug("返回的id信息", zap.Any("value", id))

	GoodsCateList, err := service.GetGoodsCateList(map[string]interface{}{"parent_id": id, "Status": 1})
	if err != nil {
		zap.L().Error("service.GetGoodsCateList() failed", zap.Error(err))
		ResponseError(c, "查询商品分类列表失败")
		return
	}
	ResponseSuccess(c, GoodsCateList)
}
